package com.zhang.backend.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhang.backend.common.response.Result;
import com.zhang.backend.entity.CommonDict;
import com.zhang.backend.service.CommonDictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/common")
public class CommonDictController {

    @Autowired
    private CommonDictService commonDictService;

    @GetMapping("/{groupId}")
    public Result<List<CommonDict>> getCommonDictByGroupId(@PathVariable Integer groupId) {
        List<CommonDict> list = commonDictService.list(
                new QueryWrapper<CommonDict>().eq("group_id", groupId)
        );
        // 使用 Result.success 包装数据，确保返回 { "code": 200, "data": [...] } 格式
        return Result.success(list);
    }
}